package com.yima.baseproj.module.sys.goods;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yima.baseproj.aop.log.Logging;
import com.yima.baseproj.module.app.lunbotu.model.AppLunbotuSearchModel;
import com.yima.baseproj.module.config.utils.PageUtil;
import com.yima.baseproj.module.config.utils.PageVo;
import com.yima.baseproj.module.config.utils.ResultUtil;
import com.yima.baseproj.module.config.utils.ResultVo;
import com.yima.baseproj.security.SecurityUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api(tags = "产品管理")
@RequestMapping("/api/sys/goods")
@RestController
public class GoodsController {

    @Autowired
    private GoodsService goodsService;

    @Logging(tags = "产品管理",value = "查询分页")
    @PreAuthorize("hasAuthority('sys:goods:findAllByPage')")
    @ApiOperation("查询分页")
    @GetMapping("/findAllByPage")
    public Object findAllByPage(PageVo page, GoodsEntity searchModel) {
        Page<Map> pageData = goodsService.findAllByPage(PageUtil.initMpPage(page),searchModel);
        return pageData;
    }

    @ApiOperation("查询列表")
    @GetMapping(value = "/findAllByList")
    public ResultVo findAllByList(GoodsEntity searchVo) {
        List<Map> list = goodsService.findByList(searchVo);
        return ResultUtil.success(list);
    }






    @Logging(tags = "产品管理",value = "添加")
    @PreAuthorize("hasAuthority('sys:goods:add')")
    @ApiOperation("添加")
    @PostMapping("/add")
    public void saveUser(@RequestBody @Validated GoodsEntity goods) {
        goodsService.add(goods);
    }

    @ApiOperation("根据id查询产品信息")
    @GetMapping("/findById/{id}")
    public GoodsEntity findById(@PathVariable int id){
        GoodsEntity goodsEntity = goodsService.findById(id);
        return goodsEntity;
    }

    @Logging(tags = "产品管理",value = "修改")
    @PreAuthorize("hasAuthority('sys:goods:edit')")
    @ApiOperation("修改")
    @PostMapping("/edit")
    public void editKg(@RequestBody @Validated GoodsEntity goods) {
        goodsService.edit(goods);
    }

    @Logging(tags = "产品管理",value = "删除")
    @PreAuthorize("hasAuthority('sys:goods:delByIds')")
    @ApiOperation("删除")
    @DeleteMapping(value = "/delByIds/{ids}")
    public void delByIds(@PathVariable int ids) {
        goodsService.delByIds(ids);
    }

}
